package com.swl.controller;

import com.swl.pojo.Topic;
import com.swl.service.TopicService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("/topic")
public class TopicController {
    @Autowired
    private TopicService topicService;
    @RequestMapping("/insertTopic")
    @ResponseBody
    public Integer addTopic(Topic topic){
        System.out.println("insertTopic执行了");
        System.out.println(topic);
        Integer i = topicService.insertTopic(topic);
        return i;
    }
    @RequestMapping("/selectAllTopic")
    @ResponseBody
    public List<Topic> selectAllTopic(){
        List<Topic> topics=topicService.selectAllTopic();
        System.out.println(topics);
        return topics;
    }

    @RequestMapping("/selectTopicByTid")
    @ResponseBody
    public Topic selectTopicByTid(@RequestParam("tid") int tid){
        System.out.println("selectTopicByTid执行了"+tid);
        return topicService.selectTopicByTid(tid);
    }
    @RequestMapping("/selectTopicBySchoolIdAndCourseId")
    @ResponseBody
    public List<Topic> selectTopicBySchoolIdAndCourseId(@RequestParam("schoolId") int schoolId,
                                                        @RequestParam("courseId") int courseId){
        System.out.println("selectTopicBySchoolIdAndCourseId执行了");

        List<Topic> topics = topicService.selectTopicBySchoolIdAndCourseId(schoolId, courseId);
        System.out.println("topics为："+topics);
        return topics;
    }
    @RequestMapping("/selectTopicBySchoolIdAndCourseIdAndDiff")
    @ResponseBody
    public List<Topic> selectTopicBySchoolIdAndCourseIdAndDiff(@RequestParam("schoolId") int schoolId,
                                                               @RequestParam("courseId") int courseId,
                                                               @RequestParam("diff") String diff){
        System.out.println("diff执行了");
        List<Topic> topics = topicService.selectTopicBySchoolIdAndCourseIdAndDiff(schoolId, courseId, diff);
        System.out.println("topics为："+topics);
        return topics;
    }
}
